package com.datasecops.scannerservices.config;

import lombok.AllArgsConstructor;
import lombok.Data;

import java.io.File;

/**
 * 文件路径配置文件
 *
 * @author: SunLingzhi
 * @time: 2022/8/16 16:37
 */
@Data
@AllArgsConstructor
public class ConfigFilePath {

    //扫描文件夹
    private static String SCANNER_DIR = "scanner";

    private static String BIN_DTR = "bin";

    //扫描exe
    private static final String SCANNER_EXE_FILE = "ScannerAgent.exe";

    //扫描引擎exe(Win)
    private static final String SCANNER_ENGINE_EXE_FILE = "ScannerEngine.exe";

    //扫描引擎sh(Linux)
    //private static final String SCANNER_ENGINE_SH_FILE = "ScannerEngine.sh";
    private static final String SCANNER_ENGINE_SH_FILE = "ScannerEngine";

    //最终调用的扫描引擎
    private static String SCANNER_ENGINE;

    //>>>>>>>>>>>>>>>>>>>>>>>策略相关资源<<<<<<<<<<<<<<<<<<<<<<
    //资源路径
    private static final String SCANNER_RESOURCE = "resource";

    //策略
    private static final String SCANNER_STRATEGY = "strategy.xml";

    //指纹库
    private static final String SCANNER_EXAMPLE = "example.zip";

    //数据字典
    private static final String SCANNER_DICTIONARIES = "dictionaries.xml";

    //机器学习库
    private static final String SCANNER_MCH_CLUSTER_PATH_DB = "MchClusterPathDB.xml";
    

    static {
        String userDir = System.getProperty("user.dir");

        File scannerDir = new File(userDir + File.separator + SCANNER_DIR);
        if (!scannerDir.exists()) {
            scannerDir.mkdir();
        }
        try {
            SCANNER_DIR = scannerDir.getCanonicalPath();
        } catch (java.io.IOException e) {
            SCANNER_DIR = scannerDir.getPath();
        }

        if(System.getProperty("os.name").toLowerCase().contains("windows")){
            SCANNER_ENGINE = SCANNER_ENGINE_EXE_FILE;
        }else{
            SCANNER_ENGINE = SCANNER_ENGINE_SH_FILE;
        }
    }

    public static String getScannerDirPath() {
        return SCANNER_DIR;
    }

    //ScannerAgent
    public static String getScannerExeFile() {
        return SCANNER_DIR + File.separator + "Bin" + File.separator + SCANNER_EXE_FILE;
    }

    //ScannerEngine
    public static String getScannerEngineExeFile() {
        //return SCANNER_DIR + File.separator + "Bin" + File.separator + SCANNER_ENGINE;
        //return BIN_DTR + File.separator + SCANNER_ENGINE;
        return BIN_DTR;
    }

    //资源路径
    public static String getScannerResource() {
        return SCANNER_RESOURCE;
    }
    //扫描策略
    public static String getScannerStrategy() {
        return SCANNER_STRATEGY;
    }

    //指纹库
    public static String getScannerExample() {
        return SCANNER_EXAMPLE;
    }

    //数据字典
    public static String getScannerDictionaries() {
        return SCANNER_DICTIONARIES;
    }

    //机器学习库
    public static String getScannerMchClusterPathDB() {
        return SCANNER_MCH_CLUSTER_PATH_DB;
    }
}
